package controllers

import play.api._
import play.api.mvc._
import play.api.data._
import play.api.data.Forms._
import play.api.libs.iteratee
import model.p_Page_Control
import play.api.templates._

case class Contact(
  name: String, 
  email: String,
  subject: String,
  phone: String,
  message: String
)

object Application extends Controller {
  
  val signupForm: Form[Contact] = Form(
    
    // Define a mapping that will handle User values
    mapping(
      "name" -> text(minLength = 4),
      "email" -> email,
      "subject" -> text,
      "phone" -> text,
      "message" -> text
    )
    // The mapping signature doesn't match the User case class signature,
    // so we have to define custom binding/unbinding functions
    {
      // Binding: Create a User from the mapping result (ignore the second password and the accept field)
      (name, email, subject, phone, message) => Contact(name, email, subject,phone, message) 
    } 
    {
      // Unbinding: Create the mapping values from an existing User value
      contact => Some(contact.name, contact.email, contact.subject, contact.phone ,contact.message)
    }
  )
  
  def about = Action {
    implicit request =>
    Ok(views.html.about(request))
  }
  
  def blog = Action {
	Ok(views.html.blog())
  }
  
  def contact = Action {
    implicit request =>
    Ok(views.html.contact(signupForm,request))
  }
  
def p_contact = Action { implicit request =>
    signupForm.bindFromRequest.fold(
        errors => Ok("ERRORS"),
        success => Ok("OK")
    )
  }

def submitpc(id: String, content: String) = Action { 
	model.p_Page_Control.update(id, content)
	Ok("Sendd")
  }
  
  def customers = Action {
    Ok(views.html.customers())
  }
  
  def index = Action {
    Ok(views.html.index())
  }
  
  def mission = Action {
    Ok(views.html.mission())
  }
  
   def products = Action {
    Ok(views.html.products())
  }
  
   def services = Action {
    Ok(views.html.services())
  }
   
  def work = Action {
    Ok(views.html.work())
  } 
  
  def draganddrop = Action{
    Ok(views.html.draganddrop())
  }
 
  
  def simple(i: String) = Action{
    Ok(views.html.tags.a("1"))
  }

  def poligon = Action{
    Ok(views.html.poligon())
  }
  def f(id:String,clientId: String): String = {
    //views.html.tags.PageContent.render(clientId)
    "Ok"
  }
}